package com.hphs.service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.hphs.info.PageInfo;
import com.hphs.mapper.CarMapper;
import com.hphs.model.VideoQuery;
import com.hphs.model.Videos;
import com.hphs.threadlocal.LocalPageInfoUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CarService {
    @Autowired
    private CarMapper carMapper;

    public List<Videos> select(VideoQuery query){
        if(query.getPageNum()!=null&& query.getPageNum()!=null) {
            PageHelper.startPage(query.getPageNum(), query.getPageSize());
        }
        List<Videos> select = carMapper.select(query);
        if(select instanceof Page){
            Page page= (Page) select;
            long total = page.getTotal();
            System.out.println(total);
            LocalPageInfoUtil.set(PageInfo.builder().Total(total).build());
        }
        return select;
    }


    public int insert(Videos videos){
        return  carMapper.insert(videos);
    }
    public int update(Videos videos){
        return carMapper.update(videos);
    }

    public int delete(Integer id){
        return carMapper.delete(id);
    }
}
